﻿@using CuongHanh
@model CuongHanh.Models.Product
@{
    ViewBag.Title = "SubCategory";
    Layout = "~/Views/Shared/_ALayout.cshtml";

}
@section script
{
    <script type="text/javascript">
        function getImage(value, record) {
            var url = '@Url.Content("~/Content/Images/Thumnail/")';
            return "<img alt='no image' src='" + url + value + "'/>";
        }

        function handlerCommand(command, record) {

            if (command == 'View') {
                var width = parseFloat('@AppUtil.WIDTH_LAGRE');
                var height = parseFloat('@AppUtil.HEIGHT_LAGRE');
                if (width > height) {
                    if (width > 500) {
                        height = (height / width) * 500;
                        width = 500;
                    }
                } else if (height > 500) {
                    width = (width / height) * 500;
                    height = 500;
                }

                var url = '@Url.Content(AppUtil.SMALL_IMAGE_PATH)';
                $('#wdImage').attr('src', '');
                $('#wdImage').width(width);
                $('#wdImage').height(height);
                $('#wdImage').attr('src', url + record.data.Image);
                window.App.wdModify.setHeight(height);
                window.App.wdModify.setWidth(width);
                window.App.wdModify.center();
                window.App.wdModify.show();
            }
        }
        function getSubCategory() {
            window.App.SubCategoryId.store.proxy.extraParams.categoryId = window.App.CategoryId.getValue();
            window.App.SubCategoryId.store.load();
        }
    </script>
}

@(Html.X()
          .TabPanel()
          .Margin(5)
          .Items(tab => tab.Add(Html.X()
                                        .Panel()
                                        .Title("Thông tin sản phẩm")
                                        .Padding(5)
                                        .Layout(LayoutType.VBox)
                                        .Items(panel => panel.Add(Html.X()
                                                                          .FormPanel()
                                                                          .ID("FormPanel1")
                                                                          .Method(HttpMethod.POST)
                                                                          .BodyPadding(10)
                                                                          .Border(false)
                                                                          .Items(form =>
                                                                                     {
                                                                                         form.Add(Html.X().HiddenFor(m => m.Id));
                                                                                         form.Add(Html.X()
                                                                                                          .HiddenFor(m => m.BranchId)
                                                                                                 );

                                                                                         form.Add(Html.X()
                                                                                                          .Panel()
                                                                                                          .Layout(LayoutType.Column)
                                                                                                          .Border(false)
                                                                                                          .Items(
                                                                                                                 column =>
                                                                                                                     {
                                                                                                                         column.Add(Html.X()
                                                                                                                                            .ComboBoxFor(m => m.CategoryId)
                                                                                                                                            .LabelWidth(120)
                                                                                                                                            .Width(400)
                                                                                                                                            .PaddingSpec("0px 20px 0px 0px")
                                                                                                                                            .ForceSelection(true)
                                                                                                                                            .DisplayField("Name")
                                                                                                                                            .ValueField("Id")
                                                                                                                                            .EmptyText("Danh mục")
                                                                                                                                            .AllowBlank(false)
                                                                                                                                            .Listeners(ls =>
                                                                                                                                                       ls.Select.Handler = "getSubCategory()"
                                                                                                                                            )
                                                                                                                                            .Store(Html.X().Store()
                                                                                                                                                           .AutoLoad(true)
                                                                                                                                                           .Model(Html.X().Model()
                                                                                                                                                                          .IDProperty("Id")
                                                                                                                                                                          .Fields(
                                                                                                                                                                                  "Id",
                                                                                                                                                                                  "Name"
                                                                                                                                                                          )
                                                                                                                                                           )
                                                                                                                                                           .Proxy(Html.X().AjaxProxy()
                                                                                                                                                                          .Json(true)
                                                                                                                                                                          .Url(Url.Action("GetCategoriesComboByBranch"))
                                                                                                                                                                          .ActionMethods(v => v.Read = HttpMethod.POST)
                                                                                                                                                                          .Reader(Html.X().JsonReader().Root("data").TotalProperty("total"))
                                                                                                                                                                          .ExtraParams(param => param.Add(new Parameter("branchId",
                                                                                                                                                                                                                        Model.BranchId + "",
                                                                                                                                                                                                                        ParameterMode.Value)))
                                                                                                                                                           )
                                                                                                                                                           .Listeners(ls =>
                                                                                                                                                                      ls.Load.Handler = "App.CategoryId.setValue(" + Model.CategoryId + ");"
                                                                                                                                                           )
                                                                                                                                            )
                                                                                                                                 );
                                                                                                                         column.Add(Html.X()
                                                                                                                                            .ComboBoxFor(m => m.SubCategoryId)
                                                                                                                                            .LabelWidth(120)
                                                                                                                                            .Width(400)
                                                                                                                                            .ForceSelection(true)
                                                                                                                                            .DisplayField("Name")
                                                                                                                                            .ValueField("Id")
                                                                                                                                            .EmptyText("Danh mục con")
                                                                                                                                            .AllowBlank(false)
                                                                                                                                            .Store(Html.X().Store()
                                                                                                                                                           .AutoLoad(true)
                                                                                                                                                           .Model(Html.X().Model()
                                                                                                                                                                          .IDProperty("Id")
                                                                                                                                                                          .Fields(
                                                                                                                                                                                  "Id",
                                                                                                                                                                                  "Name"
                                                                                                                                                                          )
                                                                                                                                                           )
                                                                                                                                                           .Proxy(Html.X().AjaxProxy()
                                                                                                                                                                          .Json(true)
                                                                                                                                                                          .Url(Url.Action("GetSubCategoriesComboByBranch"))
                                                                                                                                                                          .ActionMethods(v => v.Read = HttpMethod.POST)
                                                                                                                                                                          .Reader(Html.X().JsonReader().Root("data").TotalProperty("total"))
                                                                                                                                                                          .ExtraParams(param =>
                                                                                                                                                                                           {
                                                                                                                                                                                               param.Add(new Parameter("branchId",
                                                                                                                                                                                                                       Model.BranchId + "",
                                                                                                                                                                                                                       ParameterMode.Value));
                                                                                                                                                                                               param.Add(new Parameter("categoryId",
                                                                                                                                                                                                                       Model.CategoryId + "",
                                                                                                                                                                                                                       ParameterMode.Value));
                                                                                                                                                                                           }
                                                                                                                                                                          )
                                                                                                                                                           )
                                                                                                                                                           .Listeners(ls =>
                                                                                                                                                                      ls.Load.Handler = "App.SubCategoryId.setValue(" + Model.SubCategoryId + ");"
                                                                                                                                                           )
                                                                                                                                            )
                                                                                                                                 );
                                                                                                                     }
                                                                                                          )
                                                                                                 );

                                                                                         form.Add(Html.X()
                                                                                                          .Panel()
                                                                                                          .Layout(LayoutType.Column)
                                                                                                          .Border(false)
                                                                                                          .PaddingSpec("5px 0px 0px 0px")
                                                                                                          .Items(
                                                                                                                 column =>
                                                                                                                     {
                                                                                                                         column.Add(Html.X()
                                                                                                                                            .TextFieldFor(m => m.Code)
                                                                                                                                            .LabelWidth(120)
                                                                                                                                            .Width(400)
                                                                                                                                            .PaddingSpec("0px 20px 0px 0px")
                                                                                                                                 );
                                                                                                                         column.Add(Html.X()
                                                                                                                                            .TextFieldFor(m => m.NameVi)
                                                                                                                                            .LabelWidth(120)
                                                                                                                                            .Width(400)
                                                                                                                                 );
                                                                                                                     }
                                                                                                          )
                                                                                                 );

                                                                                         form.Add(Html.X()
                                                                                                          .Panel()
                                                                                                          .Layout(LayoutType.Column)
                                                                                                          .Border(false)
                                                                                                          .PaddingSpec("5px 0px 0px 0px")
                                                                                                          .Items(
                                                                                                                 column =>
                                                                                                                     {
                                                                                                                         column.Add(Html.X()
                                                                                                                                            .TextFieldFor(m => m.NameEn)
                                                                                                                                            .LabelWidth(120)
                                                                                                                                            .Width(400)
                                                                                                                                            .PaddingSpec("0px 20px 0px 0px")
                                                                                                                                 );
                                                                                                                         column.Add(Html.X()
                                                                                                                                            .TextFieldFor(m => m.NameZh)
                                                                                                                                            .LabelWidth(120)
                                                                                                                                            .Width(400)
                                                                                                                                 );
                                                                                                                     }
                                                                                                          )
                                                                                                 );

                                                                                         form.Add(Html.X()
                                                                                                          .Panel()
                                                                                                          .Layout(LayoutType.Column)
                                                                                                          .Border(false)
                                                                                                          .PaddingSpec("5px 0px 0px 0px")
                                                                                                          .Items(
                                                                                                                 column =>
                                                                                                                     {
                                                                                                                         column.Add(Html.X()
                                                                                                                                            .NumberFieldFor(m => m.Price)
                                                                                                                                            .LabelWidth(120)
                                                                                                                                            .Width(400)
                                                                                                                                            .PaddingSpec("0px 20px 0px 0px")
                                                                                                                                 );
                                                                                                                         column.Add(Html.X()
                                                                                                                                            .NumberFieldFor(m => m.SaleOff)
                                                                                                                                            .LabelWidth(120)
                                                                                                                                            .Width(400)
                                                                                                                                 );
                                                                                                                     }
                                                                                                          )
                                                                                                 );

                                                                                         form.Add(Html.X()
                                                                                                          .Panel()
                                                                                                          .Layout(LayoutType.Column)
                                                                                                          .Border(false)
                                                                                                          .PaddingSpec("5px 0px 0px 0px")
                                                                                                          .Items(
                                                                                                                 column =>
                                                                                                                     {
                                                                                                                         column.Add(Html.X()
                                                                                                                                            .CheckboxFor(m => m.IsShowIndex)
                                                                                                                                            .LabelWidth(120)
                                                                                                                                            .Width(400)
                                                                                                                                            .PaddingSpec("0px 20px 0px 0px")
                                                                                                                                 );
                                                                                                                         column.Add(Html.X()
                                                                                                                                            .CheckboxFor(m => m.BestSaler)
                                                                                                                                            .LabelWidth(120)
                                                                                                                                            .Width(400)
                                                                                                                                 );
                                                                                                                     }
                                                                                                          )
                                                                                                 );
                                                                                         form.Add(Html.X()
                                                                                                          .Panel()
                                                                                                          .Layout(LayoutType.Column)
                                                                                                          .Border(false)
                                                                                                          .PaddingSpec("5px 0px 0px 0px")
                                                                                                          .Items(
                                                                                                                 column =>
                                                                                                                 {
                                                                                                                     column.Add(Html.X()
                                                                                                                                        .CheckboxFor(m => m.New)
                                                                                                                                        .LabelWidth(120)
                                                                                                                                        .Width(400)
                                                                                                                                        .PaddingSpec("0px 20px 0px 0px")
                                                                                                                             );
                                                                                                                     column.Add(Html.X()
                                                                                                                                        .CheckboxFor(m => m.Invisible)
                                                                                                                                        .LabelWidth(120)
                                                                                                                                        .Width(400)
                                                                                                                             );
                                                                                                                 }
                                                                                                          )
                                                                                                 );
                                                                                         form.Add(Html.X()
                                                                                                          .Button()
                                                                                                          .ID("btUpdate")
                                                                                                          .Text("Lưu lại")
                                                                                                          .FormBind(true)
                                                                                                          .StyleSpec("margin-left:105px;")
                                                                                                          .DirectClickAction("Edit")
                                                                                                 );
                                                                                     }
                                                                          ))))))